﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace EasyConveyor.TestClient
{
	internal sealed class SlowActivator : ActivatorBase
	{
		private readonly Random _random = new Random();

		public SlowActivator(CancellationToken cancellationToken)
		{
			Task.Run(() => DoRandomActivations(cancellationToken), cancellationToken);
		}

		private void DoRandomActivations(CancellationToken cancellationToken)
		{
			while (!cancellationToken.IsCancellationRequested)
			{
				Thread.Sleep(_random.Next(1000, 5000));
				Activate(new SlowContext());
			}
		}
	}
}
